package com.zrgj.interceptor;

import com.zrgj.entity.KEY;
import com.zrgj.entity.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Component
public class LoginInter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        boolean res=true;
        HttpSession session=request.getSession();
        User user=(User)session.getAttribute(KEY.SESSION_USER);

        if(user==null){
            String cp=request.getContextPath();
            response.sendRedirect(cp+"/login.html");
            res = false;
        }else{
            res = true;
        }

        return res;
    }
}
